package controllers

import (
	beego "github.com/beego/beego/v2/server/web"
	"planet/models"
)

type AnswerController struct {
	beego.Controller
}

// 回答

func (c *AnswerController) Add() {
	questionId, _ := c.GetInt("question_id")
	content := c.GetString("content")
	answer := models.Answer{
		Content:    content,
		QuestionId: uint(questionId),
	}
	err := models.DB.Create(&answer).Error
	if err != nil {
		c.Data["json"] = JsonRes{
			Code: 0,
			Msg:  "回答失败",
			Data: nil,
		}
		c.ServeJSON()
		return
	} else {
		c.Data["json"] = JsonRes{
			Code: 200,
			Msg:  "回答成功",
			Data: nil,
		}
		c.ServeJSON()
	}
}
